<template>
    <el-form :model="Homemaster" label-width="auto" size="medium" label-position="left">  
        <el-form-item label="工号：">
            {{Homemaster.hmid}}
        </el-form-item>
        <el-form-item label="密码：">
            <el-input v-model="Homemaster.password"></el-input>
        </el-form-item>
        <el-form-item label="姓名：">
            <el-input v-model="Homemaster.name"></el-input>
        </el-form-item>
        <el-form-item label="性别：">
            <el-radio v-model="Homemaster.sex" label="男">男</el-radio>
            <el-radio v-model="Homemaster.sex" label="女">女</el-radio>
        </el-form-item>
        <el-form-item label="电话：">
            <el-input maxlength="11" v-model="Homemaster.phone"></el-input>
        </el-form-item>
        <el-form-item label="邮箱：">
            <el-input v-model="Homemaster.email"></el-input>
        </el-form-item>
        <div class="button">
            <el-form-item size="large" label-width="0">
                <el-button type="primary" @click="onSubmit(Homemaster)">修改</el-button>
            </el-form-item>
            <el-form-item size="large" label-width="0">
                <el-button type="primary" @click="cancel()">取消</el-button>
            </el-form-item>
        </div>
    </el-form>
</template>

<script>
export default {
    name:'Edithomemaster',
    data() {
        return {
            Homemaster:{},
        }
    },
    methods:{
        load(){
            let _this = this
            axios.get(`http://localhost:8081/homemaster/getHMById/${this.$route.query.hmid}`).then(function(resp){
                _this.Homemaster = resp.data
            })            
        },
        onSubmit(Homemaster){
            let _this = this
            let k = 0
            let arr = Array('qq.com','163.com','139.com','sina.com','yeah.com','126.com','21cn.com','gmail.com','yahoo.com','msn.com','hotmail.com','aol.com','ask.com','live.com','3721.net','googlemail.com','mail.com','0355.net')
            if(Homemaster.phone.length < 11 || isNaN(parseInt(Homemaster.phone)) || Homemaster.phone.slice(0,1) != '1'){
                alert('电话输入有误')
                return
            }
            if(Homemaster.email.split('@')[0] == '' || !arr.includes(Homemaster.email.split('@')[1])){
                alert('邮箱地址有误')
                return
            }
            if(Homemaster.hmid == '' || Homemaster.password == '' || Homemaster.name == '' || Homemaster.phone == '' || Homemaster.email == ''){
                alert("修改失败");
                return;
            }
            axios.get(`http://localhost:8081/homemaster/edithomemaster/${this.$route.query.hmid}`,{params:_this.Homemaster}).then(function(resp){
                alert('修改成功')
            }).catch(function(error){
                alert('修改失败')
            })
        },
        cancel(){
            this.$router.push('/homemastermannager')
        }
    },
    mounted(){
        this.load();
    }
}
</script>

<style scoped>
    .el-form{
        width: 500px;
    }
    .el-form-item{
        text-align: left;
    }
    .el-input{
        display: inline-block;
        font-size: 14px;
    }
    .bigsize{
        font-size: 20px;
    }
    .button{
        display: flex;
        justify-content: space-evenly;
    }
</style>